package view;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import controller.Maquina;
import controller.exception.MaquinaInstantiationException;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CrearMaquina extends javax.swing.JPanel {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JButton botonAceptar;
	private JLabel jLabel5;
	private JLabel jLabel4;
	private JTextField textoPrecioJug;
	private JTextField textoRecMin;
	private JTextField textoRec;
	private static CrearMaquina instancia;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new CrearMaquina());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public static CrearMaquina getInstancia()
	{
		if (instancia == null)
			instancia = new CrearMaquina();
		return instancia;
	}
	
	private CrearMaquina() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(400, 300));
			this.setLayout(null);
			{
				jLabel1 = new JLabel();
				this.add(jLabel1);
				jLabel1.setText("Pantalla de creacion de Maquina");
				jLabel1.setBounds(12, 12, 186, 25);
			}
			{
				jLabel2 = new JLabel();
				this.add(jLabel2);
				jLabel2.setText("Ingrese los datos necesarios...");
				jLabel2.setBounds(12, 36, 185, 26);
			}
			{
				textoRec = new JTextField();
				this.add(textoRec);
				textoRec.setBounds(161, 104, 94, 22);
			}
			{
				textoRecMin = new JTextField();
				this.add(textoRecMin);
				textoRecMin.setBounds(162, 151, 94, 23);
			}
			{
				textoPrecioJug = new JTextField();
				this.add(textoPrecioJug);
				textoPrecioJug.setBounds(161, 198, 94, 23);
			}
			{
				jLabel3 = new JLabel();
				this.add(jLabel3);
				jLabel3.setText("Recaudacion inicial");
				jLabel3.setBounds(31, 103, 131, 24);
			}
			{
				jLabel4 = new JLabel();
				this.add(jLabel4);
				jLabel4.setText("Recaudacion minima");
				jLabel4.setBounds(32, 150, 139, 24);
			}
			{
				jLabel5 = new JLabel();
				this.add(jLabel5);
				jLabel5.setText("Precio de jugada");
				jLabel5.setBounds(31, 198, 112, 23);
			}
			{
				botonAceptar = new JButton();
				this.add(botonAceptar);
				botonAceptar.setText("Aceptar");
				botonAceptar.setBounds(295, 256, 94, 33);
				
				botonAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt)
					{
						Float recaudacion=Float.valueOf(textoRec.getText());
						Float precioJugada=Float.valueOf(textoPrecioJug.getText());
						Float recaudacionMinima=Float.valueOf(textoRecMin.getText());
						try {
							new Maquina(recaudacion,recaudacionMinima,precioJugada);
						} catch (MaquinaInstantiationException e) {
							System.out.println("La maquina ya fue creada");
						} catch (NumberFormatException e){
							System.out.println("El valor deber�a ser Float");
						}
						
					}
				});
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
